//
//  YKBrandsGridView.h
//  YKYintaiHD
//
//  Created by user on 12-3-26.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "YKBrandsGridViewCell.h"

@protocol YKBrandsGridViewDelegate;
@protocol YKBrandsGridViewDataSource;



/*
 YKGridView 封装了网格
 网格每个单元必须高一致；宽一致，自动支持横竖版
 cell subviews 中如果有view 的话，会影响didSelectCell ，需要把view 设为 user interface disable
 */
@interface YKBrandsGridView : UIScrollView{
	id<YKBrandsGridViewDataSource> dataSource;
	id<YKBrandsGridViewDelegate> delegate_grid;
    
	NSMutableDictionary* dequeArray;			//可以重用的cell
	NSMutableDictionary* visibleCellDictionary;//当前可见的cell
	
	UIView* footerView;
	UIView* headerView;
    NSMutableArray *cellFrameArray;
    BOOL getRidOfAnimation;
    CGFloat revertFrameH;
    CGFloat headerHeight;
    
    CGFloat oldCellWidth;
    BOOL editing;
    
    CGSize gridItemSize;
    struct {
        unsigned int gridNumOfItems:1;
        unsigned int gridNumOfCol:1;
        unsigned int gridNumOfRow:1;
        unsigned int gridContentHeight:1;
        unsigned int gridContentWidth:1;
        unsigned int gridHspacer:1;
    } _gridFlags;
}
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, retain) UIView * footerView;
@property (nonatomic, retain) UIView * headerView;
@property(nonatomic,assign)    BOOL editing;
@property(nonatomic,assign) IBOutlet id<YKBrandsGridViewDataSource> dataSource;
@property(nonatomic,assign) IBOutlet id<YKBrandsGridViewDelegate> delegate_grid;
- (YKBrandsGridViewCell *) dequeueReusableCellWithIdentifier:(NSString *)identifier;

-(void) reloadFooter;

/*
 重新加载数据
 */
-(void) reloadData;

/*
 重新加载某一单元格
 */
-(void) reloadCellAtIndex:(int) index;

@end


@protocol YKBrandsGridViewDelegate <UIScrollViewDelegate>

@optional//可选
-(void) gridView:(YKBrandsGridView*) agridView willSelectCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex;				
-(void) gridView:(YKBrandsGridView*) agridView didSelectCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(YKBrandsGridView*) agridView willDisplayCell:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(YKBrandsGridView*) agridView didSelectCellUp:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex;
-(void) gridView:(YKBrandsGridView*) agridView didSelectCellOutSizeUp:(YKBrandsGridViewCell*) acell atIndex:(unsigned int) aindex;
@end



@protocol YKBrandsGridViewDataSource<NSObject>

@required //要求
-(unsigned int) numOfGridViewItem:(YKBrandsGridView*) agridView;
-(CGSize) sizeOfGridViewItem:(YKBrandsGridView*) agridView;
-(YKBrandsGridViewCell*) gridView:(YKBrandsGridView*) agridView cellForIndex:(unsigned int) aindex;

@optional
/*
 -(float) heightOfGridViewFooter:(YKGridView*) agridView;
 -(float) heightOfGridViewHeader:(YKGridView*) agridView;
 */
-(UIView*) footerOfGridView:(YKBrandsGridView*) agridView;
-(void) cellWillDisAppear:(YKBrandsGridViewCell *)agridItem;

@end

//
//@interface FrameStruct : NSObject {
//    CGFloat x;
//    CGFloat y;
//    CGFloat w;
//    CGFloat h;
//}
//@property(nonatomic,assign)    CGFloat y;
//@property(nonatomic,assign)    CGFloat w;
//@property(nonatomic,assign)    CGFloat h;
//@property(nonatomic,assign)    CGFloat x;
//-(id)setWithRect:(CGRect)rec;
//-(BOOL)isEqualToRect:(CGRect)rec;
//@end
//
